import pymysql
import jsonpath
import json
# 1.建立连接
conn = pymysql.connect(
    host="47.92.175.173",
    port=3306,
    user="qiumian",
    password="Y3ZsRL3ipGSBH47e",
    database="qiumian",
    charset="utf8",
    cursorclass=pymysql.cursors.DictCursor          #字典格式输出
)

# 2.创建游标
cur = conn.cursor()

# 3.执行SOL语句
sql = 'SELECT * FROM `user` WHERE userPhone = "15237531610"'
count = cur.execute(sql)

# 4.获取SQL语句 执行后的结果
data = cur.fetchone()   # 获取结果集当中的一条数据

# print("第一哦",data)
jsonStr = '''
          {
    "lemon": {
        "teachers": [
            {
                "id": "101",
                "name": "华华",
                "addr": "湖南长沙",
                "age": 25
            },
             {
                "id": "102",
                "name": "韬哥",
                "age": 28
            },
            {
                "id": "103",
                "name": "Happy",
                "addr": "广东深圳",
                "age": 16
            },
             {
                "id": "104",
                "name": "歪歪",
                "addr": "广东广州",
                "age": 29
            }
        ],
        "salesmans": [
            {
                "id": "105",
                "name": "毛毛",
                "age": 17
            },
             {
                "id": "106",
                "name": "大树",
                "age": 27
            }
        ]
    },
 "avg": 25
}
'''

user_1="""
        {
    "code": 200,
    "msg": "ok",
    "result": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjQ2NzA5MzEsInN1YiI6IjEyMyIsIm5iZiI6MTYyNDA2NjEzMSwiYXVkIjoidXNlcjI3IiwiaWF0IjoxNjI0MDY2MTMxLCJqdGkiOiIyMjNiZDUzMGIzYWZjYWQxNWY0ZDBiNmI3ZGI3MDJhMDU5ODkiLCJpc3MiOiJlYXN5c3dvb2xlIiwic3RhdHVzIjoxLCJkYXRhIjpudWxsfQ.u1gdSKGZK8r2nSJweftC41mNZ0hqxre9DBBRWttJsx4",
        "unique": "KKV5EKL8"
    }
}

"""

json_obj = json.loads(user_1)
token = jsonpath.jsonpath(json_obj,"$..token")
unique = jsonpath.jsonpath(json_obj,"$..unique")
# print(unique)
print(token)